package ase.eleitweg;

import com.google.inject.AbstractModule;

import java.io.FileInputStream;
import java.io.IOException;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.*;
import java.util.Properties;

import ase.eleitweg.server.*;

public class RMIModuleClient extends AbstractModule {

	@Override
	protected void configure() {
		try {
			Properties properties = new Properties();
			String serverAddr;
		    try {
		        properties.load(new FileInputStream(System.getProperty("user.dir") + "/eleitweg.properties"));
		        serverAddr = properties.getProperty("server_addr");
		    } catch (IOException e) {
		    	//serverAddr = "127.0.0.1";
		    	serverAddr = "aaa";
		    }
			Registry registry = LocateRegistry.getRegistry(serverAddr, 37445);
			UserLoginInterface uli = (UserLoginInterface) registry.lookup(UserLoginInterface.rminame);
			bind(UserLoginInterface.class).toInstance(uli);
			AdminLoginInterface ali = (AdminLoginInterface) registry.lookup(AdminLoginInterface.rminame);
			bind(AdminLoginInterface.class).toInstance(ali);
		} catch (AccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
